package com.ls.pattern.chain.predicate;

import java.util.function.Predicate;

public class Client {

    public String register(String username, String password, int age, String phone, String email) {
        Context context = new Context();
        context.setUsername(username);
        context.setPassword(password);
        context.setPhone(phone);
        context.setEmail(email);
        context.setAge(age);

        Predicate<Context> predicate = new UserNameHandler()
                .and(new AgeHandler())
                .and(new PhoneHandler().or(new EmailHandler()));
        boolean test = predicate.test(context);

        return test ? "注册成功" : "注册失败";
    }

    public static void main(String[] args) {
        Client client = new Client();
        System.out.println(client.register("张三", "123456", 18, "12345678901", ""));
        System.out.println("------------");
        System.out.println(client.register("张三", "123456", 18, "", "xxx@qq.com"));
        System.out.println("------------");
    }
}
